package object3.package4;

import java.util.Arrays;

public class Student implements Comparable<Student>{
    private String name;
    private double score;

    public Student(){
    }

    public Student(String name, double score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public int compareTo(Student o) {
        if(score > o.score){
            return 1;
        }else if(score < o.score){
            return  -1;
        }else{
            return 0;
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    public static void main(String[] args) {
        Student s1 = new Student("王双喜", 80.5);
        Student s2 = new Student("王鑫宇", 93);
        Student s3 = new Student("曾老七", 87.6);
        Student[] students = new Student[]{s1, s2, s3};
        System.out.println(Arrays.toString(students));
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));

        //String str = new String("hello world");
    }
}
